package chris.deadLetter;

import chris.ConFactory;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * DeadLetterConsumer
 *
 * @author nanxin.chen
 * @since 2017/8/2
 */
public class DeadLetterConsumer {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection con = ConFactory.getConnectionFactory().newConnection();
        Channel channel = con.createChannel();

        Consumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("consume dead letter : " + new String(body, "utf-8"));
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        };

        channel.basicConsume(DLSend.DLQueueName, consumer);

    }
}
